/********************************before-after analysis of US patents filed 98-03********************************
Main purpose: compare forward cites, citation lag, and similarity for US patents around AIPA
Datasets:
us9803: patent applications filed at the USPTO from 1998 through 2003. 

********************************before-after analysis of US patents filed 98-03********************************/


use "$DATA\us9803", clear 

//take natural log for forward cites
gen lnfcite3=ln(fcite3+1)
gen lnfcite5=ln(fcite5+1)
gen lnfcite7=ln(fcite7+1)
gen lnfcite10=ln(fcite10+1)
//take natural log for citation lags
gen lnlag1=ln(lag1app+1)
gen lnlag3=ln(lag3app+1)
gen lnlag5=ln(lag5app+1)
gen lnlag7=ln(lag7app+1)





***********************Figure 3***********************
global chg=tm(2000m12) //=491
foreach i of numlist 3 5 7 10{
preserve
keep if dpatent==1 //granted patents 
winsor2 fcite`i'
bys month: egen mean=mean(fcite`i'_w)
bys month: keep if _n==1
reg mean month if month<491 //pre-AIPA patents only
local us_cons=_b[_cons]
local us_month=_b[month]
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
(function y = `us_cons'+`us_month'*x, ra(month)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("`i'-yr forward cites", siz(medsmall)) ///
legend( region(color(white)) c(3) order(1 "Pre-AIPA" 2 "Post-AIPA" 3 "Pre-trend") size(medsmall))  xtitle("") ///
graphregion(color(white))  yla( , nogrid glc(gs14)) xsize(18) ysize(15) 
graph export "$DATA\us_fcite_pub`i'.eps", replace
restore
}




***********************Figure 4***********************
foreach i of numlist 1 3 5 7{
preserve
keep if dpatent==1 //granted patents 
winsor2 lag`i'app
bys month: egen mean=mean(lag`i'app_w)
bys month: keep if _n==1
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("Months to `i' cite(s)", siz(medsmall))  ///
legend( region(color(white)) c(3) order(1 "Pre-AIPA" 2 "Post-AIPA") size(medsmall)) ///
graphregion(color(white))  yla( , nogrid glc(gs14))  xsize(18) ysize(15) 
graph export "$DATA\us_lag`i'raw.eps", replace
restore
}



***********************Figure 5***********************
foreach i of numlist 5 10 15 25 50 75 85 90 95{
preserve
keep if dpatent==1 //granted patents 
winsor2 ipc7_`i'
bys month: egen mean=mean(ipc7_`i'_w)
bys month: keep if _n==1
reg mean month if month<491 //pre-AIPA patents only
local us_cons=_b[_cons]
local us_month=_b[month]
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
(function y = `us_cons'+`us_month'*x, ra(month)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("Similarity `i'th Pctile", siz(medsmall)) ///
legend( region(color(white)) c(3) order(1 "Pre-AIPA" 2 "Post-AIPA") size(medsmall)) ///
graphregion(color(white))  yla( , nogrid glc(gs14)) xsize(18) ysize(15) 
graph export "$DATA\us_ipc7_`i'.eps", replace
restore
}



***********************Figure 6***********************
**renewal rates
preserve
keep if dpatent==1 //granted patents only
bys month: egen fee1mean=mean(fee1)
bys month: keep if _n==1
reg fee1mean month if month<491 //pre-AIPA patents only
local us_cons=_b[_cons]
local us_month=_b[month]
graph twoway (scatter fee1mean month if month<=490) ///
(scatter fee1mean month if month>490, msymbol(triangle)) ///
(function y = `us_cons'+`us_month'*x, ra(month)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("3.5-Year Renewal(d)", siz(medsmall)) ///
legend(off) ///
graphregion(color(white))  yla( , nogrid glc(gs14)) saving(us_renew, replace) xsize(18) ysize(15) 
graph export "$DATA\us_renew.eps", replace
restore


**originality 
preserve
keep if dpatent==1 //granted patents only
winsor2 original
bys month: egen mean=mean(original_w)
bys month: keep if _n==1
reg mean month if month<491 //pre-AIPA patents only
local us_cons=_b[_cons]
local us_month=_b[month]
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
(function y = `us_cons'+`us_month'*x, ra(month)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("Originality", size(medsmall) axis(1)) ///
legend(off) ///
graphregion(color(white))  yla( , nogrid glc(gs14)) saving(us_original, replace) xsize(18) ysize(15) 
graph export "$DATA\us_original.eps", replace
restore


**claims 
preserve
keep if dpatent==1 //granted patents only
winsor2 allowed_claims
bys month: egen mean=mean(allowed_claims_w)
bys month: keep if _n==1
reg mean month if month<491 //pre-AIPA patents only
local us_cons=_b[_cons]
local us_month=_b[month]
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
(function y = `us_cons'+`us_month'*x, ra(month)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("Claims", size(medsmall) axis(1)) ///
legend(off) ///
graphregion(color(white))  yla( , nogrid glc(gs14))  xsize(18) ysize(15) 
graph export "$DATA\us_claim.eps", replace
restore

**independent claims
preserve
keep if dpatent==1 //granted patents only
winsor2 pat_clm_ct
bys month: egen mean=mean(pat_clm_ct_w)
bys month: keep if _n==1
reg mean month if month<491 //pre-AIPA patents only
local us_cons=_b[_cons]
local us_month=_b[month]
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
(function y = `us_cons'+`us_month'*x, ra(month)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("No. Independent Claims", size(medsmall) axis(1)) ///
legend( region(color(white)) c(3) order(1 "Pre-AIPA" 2 "Post-AIPA" 3 "Pre-trend") size(medsmall)) ///
graphregion(color(white))  yla( , nogrid glc(gs14)) xsize(18) ysize(15) 
graph export "$DATA\us_claim_ind.eps", replace
restore


**average words in independent claims
preserve
keep if dpatent==1 //granted patents only
winsor2 pat_wrd_ave
bys month: egen mean=mean(pat_wrd_ave_w)
bys month: keep if _n==1
reg mean month if month<491 //pre-AIPA patents only
local us_cons=_b[_cons]
local us_month=_b[month]
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
(function y = `us_cons'+`us_month'*x, ra(month)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("Independent Claim Word Length", siz(medsmall) axis(1)) ///
legend( region(color(white)) c(3) order(1 "Pre-AIPA" 2 "Post-AIPA" 3 "Pre-trend") size(medsmall)) ///
graphregion(color(white))  yla( , nogrid glc(gs14))  xsize(18) ysize(15) 
graph export "$DATA\us_claim_wrd.eps", replace
restore


**abandonment
//us9803_public.dta does not have abandonment information, hence cannot replicate this figure.
preserve
bys month: egen mean=mean(dabandon)
bys month: keep if _n==1
reg mean month if month<491 //pre-AIPA patents only
local us_cons=_b[_cons]
local us_month=_b[month]
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
(function y = `us_cons'+`us_month'*x, ra(month)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
ytitle("Abandon(d)", siz(medsmall))  ///
legend( region(color(white)) c(3) order(1 "Pre-AIPA" 2 "Post-AIPA" 3 "Pre-trend") size(medsmall)) ///
graphregion(color(white))  yla( , nogrid glc(gs14)) xsize(18) ysize(15) 
graph export "$DATA\us_abn.eps", replace
restore





****************************************Figure C1********************************************
use "$DATA\us9803", clear 
gen grant_app=iss_dt-appl_dt 
replace grant_app=. if grant_app<0 //data error
replace grant_app=grant_app/30

preserve 
keep if dpatent==1 //granted patents 
winsor2 grant_app
bys month: egen mean=mean(grant_app_w)
bys month: keep if _n==1
graph twoway (scatter mean month if month<491) ///
(scatter mean month if month>=491, msymbol(triangle) msize(medsmall)) ///
, xline(${chg}, lcolor(gray) lpattern("shortdash") lwidth(thick) ) /// 
title("Application-Grant Delay", siz(med)) ytitle("") ///
legend(off) xtitle("") ///
graphregion(color(white))  yla( , grid glc(gs14))  xsize(18) ysize(15) 
graph export "$DATA\app_grant_raw.eps", replace
restore






****************************************Table 3: summary statistics********************************************
use "$DATA\us9803",clear
#delimit ;
global sum_var1  fcite3 fcite5 fcite7 fcite10 lag1app lag3app lag5app lag7app  
ipc7_5 ipc7_10 ipc7_15 ipc7_25 ipc7_50 ipc7_75 ipc7_85 ipc7_90 ipc7_95 grant18m fee1 original  allowed_claims pat_clm_ct pat_wrd_ave;
#delimit cr
//US granted patents
tabstat $sum_var1 if dpatent==1, stat(mean sd) columns(statistics)
//US granted patents with EP parallel applications
tabstat $sum_var1 if dpatent==1 & with_ep==1, stat(mean sd) columns(statistics)

//% patents that opt out of the pre-grant publication requirement
tabstat doptout if month>=tm(2000m12), stat(mean sd median) columns(statistics)
//"us9803_public.dta" cannot replicate the following statistics
tabstat dabandon, stat(mean sd median) columns(statistics) 





//program to compute the deviation to the pre-trend
capture program drop lincom_prepost
program define lincom_prepost
	if `1'==12{
	local len=502
	}
	else if `1'==24{
	local len=514
	}
	else if `1'==18{
	local len=508
	}
	else if `1'==36{
	local len=526
	}
	else{
	local len=527
	}
	local lincom="_b[491.monthdum]"
	forvalues i=492/`len'{ //`1' is the first input from the function of lincom_window
	local lincom="`lincom'"+"+_b[`i'.monthdum]"
	}
	lincom 1/`1'*(`lincom')
end


***********************Table C1: AIPA's effect: event study analysis ***********************
use "$DATA\us9803", clear 

//take natural log for forward cites, which are only constructed for granted patents
gen lnfcite3=ln(fcite3+1)
gen lnfcite5=ln(fcite5+1)
gen lnfcite7=ln(fcite7+1)
gen lnfcite10=ln(fcite10+1)
//take natural log for citation lags, which are only constructed for granted patents
gen lnlag1=ln(lag1app+1)
gen lnlag3=ln(lag3app+1)
gen lnlag5=ln(lag5app+1)
gen lnlag7=ln(lag7app+1)


log using "$DATA\tablec1_log.txt", replace
//Panel A. forward citations
areg lnfcite3 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Fcite3Y) nocons bdec(3)  replace
lincom_prepost 37

areg lnfcite5 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Fcite5Y) nocons bdec(3) 
lincom_prepost 37

areg lnfcite7 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Fcite7Y) nocons bdec(3) 
lincom_prepost 37

areg lnfcite10 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Fcite10Y) nocons bdec(3) 
lincom_prepost 37


//Panel B: citation lags
areg lnlag1 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Lag1) nocons bdec(3)  
lincom_prepost 37

areg lnlag3 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Lag3) nocons bdec(3) 
lincom_prepost 37

areg lnlag5 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Lag5) nocons bdec(3) 
lincom_prepost 37

areg lnlag7 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Lag7) nocons bdec(3) 
lincom_prepost 37


//Panel C: similarity
areg ipc7_50 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Sim50) nocons bdec(3)  
lincom_prepost 37

areg ipc7_75 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Sim75) nocons bdec(3) 
lincom_prepost 37

areg ipc7_90 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Sim90) nocons bdec(3) 
lincom_prepost 37

areg ipc7_95 month i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec1.xls", ctitle(Sim95) nocons bdec(3) 
lincom_prepost 37
log close


***********************Table C2: control for non-linear trend in citation lags***********************
log using "$DATA\tablec2_log.txt", replace
gen month2=month^2
gen month3=month^3

//Panel A: citation lags w/ 2nd order of polynomial
areg lnlag1 month month2 i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec2.xls", ctitle(Lag1) nocons bdec(3)  
lincom_prepost 37

areg lnlag3 month month2 i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec2.xls", ctitle(Lag3) nocons bdec(3) 
lincom_prepost 37

areg lnlag5 month month2 i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec2.xls", ctitle(Lag5) nocons bdec(3) 
lincom_prepost 37

areg lnlag7 month month2 i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec2.xls", ctitle(Lag7) nocons bdec(3) 
lincom_prepost 37

//Panel B: citation lags w/ 3rd order of polynomial
areg lnlag1 month month2 month3 i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec2.xls", ctitle(Lag1) nocons bdec(3)  
lincom_prepost 37

areg lnlag3 month month2 month3 i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec2.xls", ctitle(Lag3) nocons bdec(3) 
lincom_prepost 37

areg lnlag5 month month2 month3 i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec2.xls", ctitle(Lag5) nocons bdec(3) 
lincom_prepost 37

areg lnlag7 month month2 month3 i.monthdum grant18m doptout, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec2.xls", ctitle(Lag7) nocons bdec(3) 
lincom_prepost 37
log close 


***********************Table C3: Event study analysis of patent characteristics***********************
log using "$DATA\tablec3_log.txt", replace
areg fee1 month i.monthdum doptout grant18m if dpatent==1, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec3.xls", ctitle(Renewal1) nocons bdec(3) replace 
lincom_prepost 37

areg original month i.monthdum grant18m doptout if dpatent==1, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec3.xls", ctitle(Original) nocons bdec(3) 
lincom_prepost 37

areg allowed_claims month i.monthdum grant18m doptout if dpatent==1, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec3.xls", ctitle(Clm) nocons bdec(3) 
lincom_prepost 37

areg pat_clm_ct month i.monthdum grant18m doptout if dpatent==1, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec3.xls", ctitle(IndClm) nocons bdec(3) 
lincom_prepost 37

areg pat_wrd_ave month i.monthdum grant18m doptout if dpatent==1, absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec3.xls", ctitle(IndClmWrd) nocons bdec(3) 
lincom_prepost 37

areg dabandon month i.monthdum doptout, absorb(artcls ) vce(cluster month) // "us9803_public.dta" does not contain abandoned applications, hence cannot replicate this result.
outreg2 using "$DATA\tablec3.xls", ctitle(Abn) nocons bdec(3) 
lincom_prepost 37
log close



***********************Table C4 (subsample II: with or without EP equivalents)***********************
log using "$DATA\tablec4_log.txt", replace
preserve 
keep if dpatent==1 //restricted to granted patents
drop if doptout==1 //exclude optouts 
keep if with_ep==1 //with EP equivalent
reghdfe lnfcite3 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Fcite3Y) nocons bdec(3)  replace
lincom_prepost 37

reghdfe lnfcite5 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Fcite5Y) nocons bdec(3) 
lincom_prepost 37

reghdfe lnfcite7 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Fcite7Y) nocons bdec(3) 
lincom_prepost 37

reghdfe lnfcite10 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Fcite10Y) nocons bdec(3) 
lincom_prepost 37


reghdfe lnlag1 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Lag1) nocons bdec(3)  
lincom_prepost 37

reghdfe lnlag3 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Lag3) nocons bdec(3) 
lincom_prepost 37

reghdfe lnlag5 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Lag5) nocons bdec(3) 
lincom_prepost 37

reghdfe lnlag7 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Lag7) nocons bdec(3) 
lincom_prepost 37



reghdfe ipc7_50 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Sim50) nocons bdec(3)  
lincom_prepost 37

reghdfe ipc7_75 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Sim75) nocons bdec(3) 
lincom_prepost 37

reghdfe ipc7_90 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Sim90) nocons bdec(3) 
lincom_prepost 37

reghdfe ipc7_95 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Sim95) nocons bdec(3) 
lincom_prepost 37
restore 



preserve 
keep if dpatent==1 //restricted to granted patents
drop if doptout==1 //exclude optouts 
keep if with_ep==0 //without EP equivalent
reghdfe lnfcite3 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Fcite3Y) nocons bdec(3)  replace
lincom_prepost 37

reghdfe lnfcite5 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Fcite5Y) nocons bdec(3) 
lincom_prepost 37

reghdfe lnfcite7 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Fcite7Y) nocons bdec(3) 
lincom_prepost 37

reghdfe lnfcite10 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Fcite10Y) nocons bdec(3) 
lincom_prepost 37


reghdfe lnlag1 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Lag1) nocons bdec(3)  
lincom_prepost 37

reghdfe lnlag3 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Lag3) nocons bdec(3) 
lincom_prepost 37

reghdfe lnlag5 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Lag5) nocons bdec(3) 
lincom_prepost 37

reghdfe lnlag7 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Lag7) nocons bdec(3) 
lincom_prepost 37



reghdfe ipc7_50 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Sim50) nocons bdec(3)  
lincom_prepost 37

reghdfe ipc7_75 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Sim75) nocons bdec(3) 
lincom_prepost 37

reghdfe ipc7_90 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Sim90) nocons bdec(3) 
lincom_prepost 37

reghdfe ipc7_95 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec4.xls", ctitle(Sim95) nocons bdec(3) 
lincom_prepost 37
rm "$DATA\tablec4.txt"
restore 
log close






************************************************pre-post analyses:with or without foreign parallel, excluding optouts************************************************
log using "$DATA\tablec5_log.txt", replace
preserve 
keep if dpatent==1 //restricted to granted patents
drop if doptout==1 //exclude optouts 
keep if with_for==1 //with foreign parallel applications
qui: reghdfe lnfcite3 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Fcite3Y) nocons bdec(3)  replace
lincom_prepost 37

qui:  reghdfe lnfcite5 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Fcite5Y) nocons bdec(3) 
lincom_prepost 37

qui:  reghdfe lnfcite7 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Fcite7Y) nocons bdec(3) 
lincom_prepost 37

qui:  reghdfe lnfcite10 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Fcite10Y) nocons bdec(3) 
lincom_prepost 37


qui: reghdfe lnlag1 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Lag1) nocons bdec(3)  
lincom_prepost 37

qui: reghdfe lnlag3 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Lag3) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe lnlag5 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Lag5) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe lnlag7 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Lag7) nocons bdec(3) 
lincom_prepost 37


qui: reghdfe ipc7_50 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Sim50) nocons bdec(3)  
lincom_prepost 37

qui: reghdfe ipc7_75 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Sim75) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe ipc7_90 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Sim90) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe ipc7_95 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Sim95) nocons bdec(3) 
lincom_prepost 37
restore 


preserve 
keep if dpatent==1 //restricted to granted patents
drop if doptout==1 //exclude optouts 
keep if with_for==0 //without foreign parallel applications
qui: reghdfe lnfcite3 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Fcite3Y) nocons bdec(3)  replace
lincom_prepost 37

qui: reghdfe lnfcite5 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Fcite5Y) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe lnfcite7 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Fcite7Y) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe lnfcite10 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Fcite10Y) nocons bdec(3) 
lincom_prepost 37


qui: reghdfe lnlag1 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Lag1) nocons bdec(3)  
lincom_prepost 37

qui: reghdfe lnlag3 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Lag3) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe lnlag5 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Lag5) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe lnlag7 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Lag7) nocons bdec(3) 
lincom_prepost 37



qui: reghdfe ipc7_50 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Sim50) nocons bdec(3)  
lincom_prepost 37

qui: reghdfe ipc7_75 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Sim75) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe ipc7_90 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Sim90) nocons bdec(3) 
lincom_prepost 37

qui: reghdfe ipc7_95 month i.monthdum grant18m , absorb(artcls ) vce(cluster month)
outreg2 using "$DATA\tablec5.xls", ctitle(Sim95) nocons bdec(3) 
lincom_prepost 37
rm "$DATA\tablec5.txt"
restore 
log close






